package tool

import (
	"reflect"
	"encoding/json"
)

func Struct2Map(obj interface{}) map[string]interface{} {
	t := reflect.TypeOf(obj)
	v := reflect.ValueOf(obj)
	//fmt.Println(t.String())
	var data = make(map[string]interface{})
	for i := 0; i < t.NumField(); i++ {
		data[t.Field(i).Name] = v.Field(i).Interface()
	}
	return data
}

func MapMarshal(data map[string]interface{}) string {
	m,err:=json.Marshal(data)
	if err != nil {
		return ""
	}
	return string(m)
}

